<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>Implementing Container Actors</title>
    <link rel="stylesheet" href="style.css" type="text/css" />
    <meta name="generator" content="DocBook XSL Stylesheets V1.73.2" />
    <link rel="start" href="index.html" title="Clutter编程" />
    <link rel="up" href="appendix-implementing-actors.html" title="Appendix A. Implementing Actors" />
    <link rel="prev" href="custom-actor-example.html" title="Example" />
    <link rel="next" href="custom-container-example.html" title="Example" />
  </head>
  <body>
    <div class="navheader">
      <table width="100%" summary="Navigation header">
        <tr>
          <th colspan="3" align="center">Implementing Container Actors</th>
        </tr>
        <tr>
          <td width="20%" align="left"><a accesskey="p" href="custom-actor-example.html"><img src="../icons/prev.png" alt="Prev" /></a> </td>
          <th width="60%" align="center">Appendix A. Implementing Actors</th>
          <td width="20%" align="right"> <a accesskey="n" href="custom-container-example.html"><img src="../icons/next.png" alt="Next" /></a></td>
        </tr>
      </table>
      <hr />
    </div>
    <div class="sect1" lang="en" xml:lang="en">
      <div class="titlepage">
        <div>
          <div>
            <h2 class="title" style="clear: both"><a id="appendix-implementing-actors-containers"></a>Implementing Container Actors</h2>
          </div>
        </div>
      </div>
      <p>
You can create container actors that arrange child actors by implementing the 
ClutterContainer interface in your actor. You may use the <code class="function">G_DEFINE_TYPE_WITH_CODE</code> 
macro to specify that the type is derived from <code class="classname">ClutterActor</code> 
and also implements the <code class="classname">ClutterContainer</code> interface. For instance:
</p>
      <pre class="programlisting">
static void clutter_container_iface_init (ClutterContainerIface *iface);

G_DEFINE_TYPE_WITH_CODE (ExampleContainer, example_container, CLUTTER_TYPE_ACTOR,
                         G_IMPLEMENT_INTERFACE (CLUTTER_TYPE_CONTAINER,
                                                clutter_container_iface_init));
</pre>
      <p>
</p>
      <div class="sect2" lang="en" xml:lang="en">
        <div class="titlepage">
          <div>
            <div>
              <h3 class="title"><a id="id2989451"></a>ClutterActor virtual functions to implement</h3>
            </div>
          </div>
        </div>
        <p>If your container should control the position or size of its children then 
it should implement the <code class="classname">ClutterActor</code>'s 
<code class="function">allocate()</code>, <code class="function">get_preferred_width()</code> and 
<code class="function">get_preferred_height()</code> virtual functions.</p>
        <p>For instance, your <code class="function">allocate()</code> implementation should 
use the provided allocation to layout its child actors, by calling 
<code class="function">clutter_actor_allocate()</code> on each child actor with appropriate 
allocations.
</p>
        <p>Your <code class="function">get_preferred_width()</code> and 
<code class="function">get_preferred_height()</code> implementations should 
return the size desired by your container, by providing both the minimum and
natural size as output parameters. Depending on your 
container, this might be dependent on the child actors. By calling
<code class="function">clutter_actor_get_preferred_size()</code> you can discover the preferred
height and width of a child actor.</p>
        <p>Your actor should implement one of two geometry management modes - either height 
for width (<code class="literal">CLUTTER_REQUEST_HEIGHT_FOR_WIDTH</code>) or width for height 
<code class="literal">CLUTTER_REQUEST_WIDTH_FOR_HEIGHT</code>) and should set its 
<code class="literal">request-mode</code> property to indicate which one it uses. For instance, in 
height-for-width mode, the parent actor first asks for the preferred height and then asks for 
a preferred width appropriate for that height. <code class="function">clutter_actor_get_preferred_size()</code> 
checks this property and then calls either <code class="function">clutter_actor_get_preferred_width()</code> 
or <code class="function">clutter_actor_get_preferred_height()</code> in the correct sequence.
</p>
        <p>You should implement the <code class="function">paint()</code> function, usually 
calling <code class="function">clutter_actor_paint()</code> on the child actors. All 
containers should also implement the <code class="function">pick()</code> function, calling 
<code class="function">clutter_actor_pick()</code> on each child actor.</p>
        <p>See the <a class="link" href="appendix-implementing-actors.html" title="Appendix A. Implementing Actors">Custom Actor</a> 
section for more details these virtual functions.</p>
      </div>
      <div class="sect2" lang="en" xml:lang="en">
        <div class="titlepage">
          <div>
            <div>
              <h3 class="title"><a id="id2989610"></a>ClutterContainer virtual functions to implement</h3>
            </div>
          </div>
        </div>
        <p>Your container implementation should also implement some of the 
<code class="classname">ClutterContainer</code> virtual functions so that the container's 
children will be affected appropriately when functions are called on the container.  
</p>
        <p>For instance, your <code class="function">add()</code> and 
<code class="function">remove()</code> implementions should manage your container's 
internal list of child actors and might need to trigger repositioning or 
resizing of the child actors by calling
<code class="function">clutter_actor_queue_relayout()</code>.
</p>
        <p>Your <code class="function">foreach</code> implementation would simply call the 
provided callback on your container's list of child actors. Note that your container 
could actually contain additional actors that are not considered to be child 
actors for the purposes of add(), remove(), and foreach().</p>
      </div>
    </div>
    <div class="navfooter">
      <hr />
      <table width="100%" summary="Navigation footer">
        <tr>
          <td width="40%" align="left"><a accesskey="p" href="custom-actor-example.html"><img src="../icons/prev.png" alt="Prev" /></a> </td>
          <td width="20%" align="center">
            <a accesskey="u" href="appendix-implementing-actors.html">
              <img src="../icons/up.png" alt="Up" />
            </a>
          </td>
          <td width="40%" align="right"> <a accesskey="n" href="custom-container-example.html"><img src="../icons/next.png" alt="Next" /></a></td>
        </tr>
        <tr>
          <td width="40%" align="left" valign="top">Example </td>
          <td width="20%" align="center">
            <a accesskey="h" href="index.html">
              <img src="../icons/home.png" alt="Home" />
            </a>
          </td>
          <td width="40%" align="right" valign="top"> Example</td>
        </tr>
      </table>
    </div>
  </body>
</html>
